package com.example.dziennikposilkow;


import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class TabelaProdukty2 extends DziennikMainActivity implements ScrollViewListener {
    /** Called when the activity is first created. */
    TableLayout country_table;
    TableLayout name_table;

    ObservableScrollView scrollView1;
    ObservableScrollView scrollView2;

    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
	setContentView(R.layout.activity_tabela_produkty);
	country_table = (TableLayout) findViewById(R.id.country_table);
	name_table = (TableLayout) findViewById(R.id.name_table);

	scrollView1 = (ObservableScrollView) findViewById(R.id.ScrollView1);
	scrollView2 = (ObservableScrollView) findViewById(R.id.ScrollView2);
	scrollView1.setScrollViewListener(this);
	scrollView2.setScrollViewListener(this);

	fillCountryTable();
	fillNameTable();
    }

    void scrollView() {

    }

    void fillCountryTable() {

	TableRow row;
	TextView t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14,
	t15, t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29,
	t30, t31, t32, t33;
	
	View v1;
	// Converting to dip unit
	int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
		(float) 1, getResources().getDisplayMetrics());

	for (int current = 0; current < CountriesList.abbreviations.length; current++) {
	    row = new TableRow(this);

	    
	    if (current%2 == 0){
	    t1 = new TextView(this);
	    t1.setTextColor(getResources().getColor(R.color.dark_red));
	    t2 = new TextView(this);
	    t2.setTextColor(getResources().getColor(R.color.dark_red));
	    t3 = new TextView(this);
	    t3.setTextColor(getResources().getColor(R.color.dark_red));
	    t4 = new TextView(this);
	    t4.setTextColor(getResources().getColor(R.color.dark_red));
	    t5 = new TextView(this);
	    t5.setTextColor(getResources().getColor(R.color.dark_red));
	    t6 = new TextView(this);
	    t6.setTextColor(getResources().getColor(R.color.dark_red));
	    t7 = new TextView(this);
	    t7.setTextColor(getResources().getColor(R.color.dark_red));
	    t8 = new TextView(this);
	    t8.setTextColor(getResources().getColor(R.color.dark_red));
	    t9 = new TextView(this);
	    t9.setTextColor(getResources().getColor(R.color.dark_red));
	    t10 = new TextView(this);
	    t10.setTextColor(getResources().getColor(R.color.dark_red));
	    t11 = new TextView(this);
	    t11.setTextColor(getResources().getColor(R.color.dark_red));
	    t12 = new TextView(this);
	    t12.setTextColor(getResources().getColor(R.color.dark_red));
	    t13 = new TextView(this);
	    t13.setTextColor(getResources().getColor(R.color.dark_red));
	    t14 = new TextView(this);
	    t14.setTextColor(getResources().getColor(R.color.dark_red));
	    t15 = new TextView(this);
	    t15.setTextColor(getResources().getColor(R.color.dark_red));
	    t16 = new TextView(this);
	    t16.setTextColor(getResources().getColor(R.color.dark_red));
	    t17 = new TextView(this);
	    t17.setTextColor(getResources().getColor(R.color.dark_red));
	    t18 = new TextView(this);
	    t18.setTextColor(getResources().getColor(R.color.dark_red));
	    t19 = new TextView(this);
	    t19.setTextColor(getResources().getColor(R.color.dark_red));
	    t20 = new TextView(this);
	    t20.setTextColor(getResources().getColor(R.color.dark_red));
	    t21 = new TextView(this);
	    t21.setTextColor(getResources().getColor(R.color.dark_red));
	    t22 = new TextView(this);
	    t22.setTextColor(getResources().getColor(R.color.dark_red));
	    t23 = new TextView(this);
	    t23.setTextColor(getResources().getColor(R.color.dark_red));
	    t24 = new TextView(this);
	    t24.setTextColor(getResources().getColor(R.color.dark_red));
	    t25 = new TextView(this);
	    t25.setTextColor(getResources().getColor(R.color.dark_red));
	    t26 = new TextView(this);
	    t26.setTextColor(getResources().getColor(R.color.dark_red));
	    t27 = new TextView(this);
	    t27.setTextColor(getResources().getColor(R.color.dark_red));
	    t28 = new TextView(this);
	    t28.setTextColor(getResources().getColor(R.color.dark_red));
	    t29 = new TextView(this);
	    t29.setTextColor(getResources().getColor(R.color.dark_red));
	    t30 = new TextView(this);
	    t30.setTextColor(getResources().getColor(R.color.dark_red));
	    t31 = new TextView(this);
	    t31.setTextColor(getResources().getColor(R.color.dark_red));
	    t32 = new TextView(this);
	    t32.setTextColor(getResources().getColor(R.color.dark_red));
	    t33 = new TextView(this);
	    t33.setTextColor(getResources().getColor(R.color.dark_red));
	    }
	    else {
	    	 t1 = new TextView(this);
	 	    t1.setTextColor(getResources().getColor(R.color.blue));
	 	    t2 = new TextView(this);
	 	    t2.setTextColor(getResources().getColor(R.color.blue));
	 	    t3 = new TextView(this);
	 	    t3.setTextColor(getResources().getColor(R.color.blue));
	 	    t4 = new TextView(this);
	 	    t4.setTextColor(getResources().getColor(R.color.blue));
	 	    t5 = new TextView(this);
	 	    t5.setTextColor(getResources().getColor(R.color.blue));
	 	    t6 = new TextView(this);
	 	    t6.setTextColor(getResources().getColor(R.color.blue));
	 	    t7 = new TextView(this);
	 	    t7.setTextColor(getResources().getColor(R.color.blue));
	 	    t8 = new TextView(this);
	 	    t8.setTextColor(getResources().getColor(R.color.blue));
	 	    t9 = new TextView(this);
	 	    t9.setTextColor(getResources().getColor(R.color.blue));
	 	    t10 = new TextView(this);
	 	    t10.setTextColor(getResources().getColor(R.color.blue));
	 	    t11 = new TextView(this);
	 	    t11.setTextColor(getResources().getColor(R.color.blue));
	 	    t12 = new TextView(this);
	 	    t12.setTextColor(getResources().getColor(R.color.blue));
	 	    t13 = new TextView(this);
	 	    t13.setTextColor(getResources().getColor(R.color.blue));
	 	    t14 = new TextView(this);
	 	    t14.setTextColor(getResources().getColor(R.color.blue));
	 	    t15 = new TextView(this);
	 	    t15.setTextColor(getResources().getColor(R.color.blue));
	 	    t16 = new TextView(this);
	 	    t16.setTextColor(getResources().getColor(R.color.blue));
	 	    t17 = new TextView(this);
	 	    t17.setTextColor(getResources().getColor(R.color.blue));
	 	    t18 = new TextView(this);
	 	    t18.setTextColor(getResources().getColor(R.color.blue));
	 	    t19 = new TextView(this);
	 	    t19.setTextColor(getResources().getColor(R.color.blue));
	 	    t20 = new TextView(this);
	 	    t20.setTextColor(getResources().getColor(R.color.blue));
	 	    t21 = new TextView(this);
	 	    t21.setTextColor(getResources().getColor(R.color.blue));
	 	    t22 = new TextView(this);
	 	    t22.setTextColor(getResources().getColor(R.color.blue));
	 	    t23 = new TextView(this);
	 	    t23.setTextColor(getResources().getColor(R.color.blue));
	 	    t24 = new TextView(this);
	 	    t24.setTextColor(getResources().getColor(R.color.blue));
	 	    t25 = new TextView(this);
	 	    t25.setTextColor(getResources().getColor(R.color.blue));
	 	    t26 = new TextView(this);
	 	    t26.setTextColor(getResources().getColor(R.color.blue));
	 	    t27 = new TextView(this);
	 	    t27.setTextColor(getResources().getColor(R.color.blue));
	 	    t28 = new TextView(this);
	 	    t28.setTextColor(getResources().getColor(R.color.blue));
	 	    t29 = new TextView(this);
	 	    t29.setTextColor(getResources().getColor(R.color.blue));
	 	    t30 = new TextView(this);
	 	    t30.setTextColor(getResources().getColor(R.color.blue));
	 	    t31 = new TextView(this);
	 	    t31.setTextColor(getResources().getColor(R.color.blue));
	 	    t32 = new TextView(this);
	 	    t32.setTextColor(getResources().getColor(R.color.blue));
	 	    t33 = new TextView(this);
	 	    t33.setTextColor(getResources().getColor(R.color.blue));	
	    	
	    }
	  
	    
	    
	    
	    
	    
	    
	    

	    t1.setText(CountriesList.abbreviations[current]);
	    t2.setText(CountriesList.countries[current]);
	    t3.setText(CountriesList.countries[current]);
	    t4.setText(CountriesList.abbreviations[current]);
	    t5.setText(CountriesList.abbreviations[current]);
	    t6.setText(CountriesList.countries[current]);
	    t7.setText(CountriesList.abbreviations[current]);
	    t8.setText(CountriesList.countries[current]);
	    t9.setText(CountriesList.countries[current]);
	    t10.setText(CountriesList.abbreviations[current]);
	    t11.setText(CountriesList.countries[current]);
	    t12.setText(CountriesList.countries[current]);
	    t13.setText(CountriesList.abbreviations[current]);
	    t14.setText(CountriesList.countries[current]);
	    t15.setText(CountriesList.countries[current]);
	    t16.setText(CountriesList.abbreviations[current]);
	    t17.setText(CountriesList.countries[current]);
	    t18.setText(CountriesList.countries[current]);
	    t19.setText(CountriesList.abbreviations[current]);
	    t20.setText(CountriesList.countries[current]);
	    t21.setText(CountriesList.countries[current]);
	    t22.setText(CountriesList.abbreviations[current]);
	    t23.setText(CountriesList.countries[current]);
	    t24.setText(CountriesList.countries[current]);
	    t25.setText(CountriesList.abbreviations[current]);
	    t26.setText(CountriesList.countries[current]);
	    t27.setText(CountriesList.countries[current]);
	    t28.setText(CountriesList.abbreviations[current]);
	    t29.setText(CountriesList.abbreviations[current]);
	    t30.setText(CountriesList.abbreviations[current]);
	    t31.setText(CountriesList.abbreviations[current]);
	    t32.setText(CountriesList.abbreviations[current]);
	    t33.setText(CountriesList.abbreviations[current]);
	    

	    t1.setTypeface(null, 1);
	    t2.setTypeface(null, 1);
	    t3.setTypeface(null, 1);
	    t4.setTypeface(null, 1);
	    t5.setTypeface(null, 1);
	    t6.setTypeface(null, 1);
	    t7.setTypeface(null, 1);
	    t8.setTypeface(null, 1);
	    t9.setTypeface(null, 1);
	    t10.setTypeface(null, 1);
	    t11.setTypeface(null, 1);
	    t12.setTypeface(null, 1);
	    t13.setTypeface(null, 1);
	    t14.setTypeface(null, 1);
	    t15.setTypeface(null, 1);
	    t16.setTypeface(null, 1);
	    t17.setTypeface(null, 1);
	    t18.setTypeface(null, 1);
	    t19.setTypeface(null, 1);
	    t20.setTypeface(null, 1);
	    t21.setTypeface(null, 1);
	    t22.setTypeface(null, 1);
	    t23.setTypeface(null, 1);
	    t24.setTypeface(null, 1);
	    t25.setTypeface(null, 1);
	    t26.setTypeface(null, 1);
	    t27.setTypeface(null, 1);
	    t28.setTypeface(null, 1);
	    t29.setTypeface(null, 1);
	    t30.setTypeface(null, 1);
	    t31.setTypeface(null, 1);
	    t32.setTypeface(null, 1);
	    t33.setTypeface(null, 1);
	    
	    
	    
	    
	    

	    t1.setTextSize(18);
	    t2.setTextSize(18);
	    t3.setTextSize(18);
	    t4.setTextSize(18);
	    t5.setTextSize(18);
	    t6.setTextSize(18);
	    t7.setTextSize(18);
	    t8.setTextSize(18);
	    t9.setTextSize(18);
	    t10.setTextSize(18);
	    t11.setTextSize(18);
	    t12.setTextSize(18);
	    t13.setTextSize(18);
	    t14.setTextSize(18);
	    t15.setTextSize(18);
	    t16.setTextSize(18);
	    t17.setTextSize(18);
	    t18.setTextSize(18);
	    t19.setTextSize(18);
	    t20.setTextSize(18);
	    t21.setTextSize(18);
	    t22.setTextSize(18);
	    t23.setTextSize(18);
	    t24.setTextSize(18);
	    t25.setTextSize(18);
	    t26.setTextSize(18);
	    t27.setTextSize(18);
	    t28.setTextSize(18);
	    t29.setTextSize(18);
	    t30.setTextSize(18);
	    t31.setTextSize(18);
	    t32.setTextSize(18);
	    t33.setTextSize(18);
	 


	    t1.setWidth(130 * dip);
	    t2.setWidth(130 * dip);
	    t3.setWidth(150 * dip);
	    t4.setWidth(160 * dip);
	    t5.setWidth(150 * dip);
	    t6.setWidth(200 * dip);
	    t7.setWidth(200 * dip);
	    t8.setWidth(150 * dip);
	    t9.setWidth(110 * dip);
	    t10.setWidth(150 * dip);
	    t11.setWidth(150 * dip);
	    t12.setWidth(150 * dip);
	    t13.setWidth(150 * dip);
	    t14.setWidth(150 * dip);
	    t15.setWidth(150 * dip);
	    t16.setWidth(150 * dip);
	    t17.setWidth(150 * dip);
	    t18.setWidth(150 * dip);
	    t19.setWidth(150 * dip);
	    t20.setWidth(150 * dip);
	    t21.setWidth(150 * dip);
	    t22.setWidth(150 * dip);
	    t23.setWidth(150 * dip);
	    t24.setWidth(200 * dip);
	    t25.setWidth(110 * dip);
	    t26.setWidth(110 * dip);
	    t27.setWidth(110 * dip);
	    t28.setWidth(110 * dip);
	    t29.setWidth(110 * dip);
	    t30.setWidth(110 * dip);
	    t31.setWidth(110 * dip);
	    t32.setWidth(150 * dip);
	    t33.setWidth(150 * dip);
	    
	    

	    t1.setPadding(0, 0, 0, 15);
	    t2.setPadding(0, 0, 0, 15);
	    t3.setPadding(0, 0, 0, 15);
	    t4.setPadding(0, 0, 0, 15);
	    t5.setPadding(0, 0, 0, 15);
	    t6.setPadding(0, 0, 0, 15);
	    t7.setPadding(0, 0, 0, 15);
	    t8.setPadding(0, 0, 0, 15);
	    t9.setPadding(0, 0, 0, 15);
	    t10.setPadding(0, 0, 0, 15);
	    t11.setPadding(0, 0, 0, 15);
	    t12.setPadding(0, 0, 0, 15);
	    t13.setPadding(0, 0, 0, 15);
	    t14.setPadding(0, 0, 0, 15);
	    t15.setPadding(0, 0, 0, 15);
	    t16.setPadding(0, 0, 0, 15);
	    t17.setPadding(0, 0, 0, 15);
	    t18.setPadding(0, 0, 0, 15);
	    t19.setPadding(0, 0, 0, 15);
	    t20.setPadding(0, 0, 0, 15);
	    t21.setPadding(0, 0, 0, 15);
	    t22.setPadding(0, 0, 0, 15);
	    t23.setPadding(0, 0, 0, 15);
	    t24.setPadding(0, 0, 0, 15);
	    t25.setPadding(0, 0, 0, 15);
	    t26.setPadding(0, 0, 0, 15);
	    t27.setPadding(0, 0, 0, 15);
	    t28.setPadding(0, 0, 0, 15);
	    t29.setPadding(0, 0, 0, 15);
	    t30.setPadding(0, 0, 0, 15);
	    t31.setPadding(0, 0, 0, 15);
	    t32.setPadding(0, 0, 0, 15);
	    t33.setPadding(0, 0, 0, 15);
	    
	    row.addView(t1);
	    row.addView(t2);
	    row.addView(t3);
	    row.addView(t4);
	    row.addView(t5);
	    row.addView(t6);
	    row.addView(t7);
	    row.addView(t8);
	    row.addView(t9);
	    row.addView(t10);
	    row.addView(t11);
	    row.addView(t12);
	    row.addView(t13);
	    row.addView(t14);
	    row.addView(t15);
	    row.addView(t16);
	    row.addView(t17);
	    row.addView(t18);
	    row.addView(t19);
	    row.addView(t20);
	    row.addView(t21);
	    row.addView(t22);
	    row.addView(t23);
	    row.addView(t24);
	    row.addView(t25);
	    row.addView(t26);
	    row.addView(t27);
	    row.addView(t28);
	    row.addView(t29);
	    row.addView(t30);
	    row.addView(t31);
	    row.addView(t32);
	    row.addView(t33);
	    
	    
	    


	    country_table.addView(row, new TableLayout.LayoutParams(
		    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
	    
	    
	}
	
    }

    void fillNameTable() {
	TableRow row;
	TextView t_name;
	// Converting to dip unit
	int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
		(float) 1, getResources().getDisplayMetrics());

	for (int current = 0; current < CountriesList.abbreviations.length; current++) {
	    row = new TableRow(this);

	    t_name = new TextView(this);
	    if (current % 2 == 0){
	    t_name.setTextColor(getResources().getColor(R.color.dark_red));
	    }
	    else {
	    	 t_name.setTextColor(getResources().getColor(R.color.blue));
	    }

	    t_name.setText(CountriesList.countries[current]);

	    t_name.setTypeface(null, 1);

	    t_name.setTextSize(18);

	    t_name.setWidth(300 * dip);

	    row.addView(t_name);
	    
	    t_name.setPadding(0, 0, 0, 15);

	    name_table.addView(row, new TableLayout.LayoutParams(
		    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
	    

		//t_name.setOnTouchListener(new CustomTouchListener());
	  
	}
    }

    public void onScrollChanged(ObservableScrollView scrollView, int x, int y,
	    int oldx, int oldy) {

	if (scrollView == scrollView1) {
	    scrollView2.scrollTo(x, y);
	} else if (scrollView == scrollView2) {
	    scrollView1.scrollTo(x, y);
	}

    }
}